<template>
  <div class="container h-100">
    <div class="d-flex justify-content-center ">
      <el-form class="m-auto">
        <el-form-item label="账号">
          <el-input placeholder="请输入内容" v-model="username" clearable></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input placeholder="请输入内容" v-model="password" clearable show-password></el-input>
        </el-form-item>
        <div class="d-flex justify-content-center">
          <el-button type="primary" @click="login">登陆</el-button>
        </div>
        <div class="text-secondary">
          没有账号,去<a :href="SYS_REGISTER_URL" class="btn small text-primary text-decoration-underline">注册</a>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import {userLogin} from "@/api/user";
import {USER_REGISTER_URL} from "@/views/user/index";
import {SYS_HOME} from "@/index.js";

export default {
  name: "loginComponent",
  data() {
    return {
      SYS_REGISTER_URL: USER_REGISTER_URL,
      from: this.$route.query.from || SYS_HOME,
      username: "",
      password: "",
    }
  },
  methods: {
    async login() {
      let data = {
        "username": this.username,
        "password": this.password,
      }
      let res = await userLogin(data)
      if (res.code === 1) {
        this.$message.success('登录成功');
        await this.$router.back()
      } else {
        this.$message.error('登陆失败,请重新检查账号密码');
      }
    }
  }
}
</script>

<style scoped>

</style>
